package com.hig.ledger.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hig.ledger.mapper.LedgerSafetyValveMapper;
import com.hig.ledger.domain.LedgerSafetyValve;
import com.hig.ledger.service.ILedgerSafetyValveService;

/**
 * 安全阀台账Service业务层处理
 *
 * @author scp
 * @date 2024-09-20
 */
@Service
public class LedgerSafetyValveServiceImpl implements ILedgerSafetyValveService
{
    @Autowired
    private LedgerSafetyValveMapper ledgerSafetyValveMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询安全阀台账
     *
     * @param id 安全阀台账ID
     * @return 安全阀台账
     */
    @Override
    public LedgerSafetyValve selectLedgerSafetyValveById(Long id)
    {
        return ledgerSafetyValveMapper.selectLedgerSafetyValveById(id);
    }

    /**
     * 查询安全阀台账列表
     *
     * @param ledgerSafetyValve 安全阀台账
     * @return 安全阀台账
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<LedgerSafetyValve> selectLedgerSafetyValveList(LedgerSafetyValve ledgerSafetyValve)
    {
        return ledgerSafetyValveMapper.selectLedgerSafetyValveList(ledgerSafetyValve);
    }

    /**
     * 新增安全阀台账
     *
     * @param ledgerSafetyValve 安全阀台账
     * @return 结果
     */
    @Override
    public int insertLedgerSafetyValve(LedgerSafetyValve ledgerSafetyValve)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ledgerSafetyValve.setCreateBy(loginUser.getUser().getUserName());
        ledgerSafetyValve.setDeptId(loginUser.getUser().getDeptId());
//        long valveId = ledgerSafetyValveMapper.getNextValveId();
//        ledgerSafetyValve.setId(valveId);
        ledgerSafetyValve.setCreateTime(DateUtils.getNowDate());
        return ledgerSafetyValveMapper.insertLedgerSafetyValve(ledgerSafetyValve);
    }

    /**
     * 修改安全阀台账
     *
     * @param ledgerSafetyValve 安全阀台账
     * @return 结果
     */
    @Override
    public int updateLedgerSafetyValve(LedgerSafetyValve ledgerSafetyValve)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ledgerSafetyValve.setUpdateBy(loginUser.getUser().getUserName());
        ledgerSafetyValve.setUpdateTime(DateUtils.getNowDate());
        return ledgerSafetyValveMapper.updateLedgerSafetyValve(ledgerSafetyValve);
    }

    /**
     * 批量删除安全阀台账
     *
     * @param ids 需要删除的安全阀台账ID
     * @return 结果
     */
    @Override
    public int deleteLedgerSafetyValveByIds(Long[] ids)
    {
        return ledgerSafetyValveMapper.deleteLedgerSafetyValveByIds(ids);
    }

    /**
     * 删除安全阀台账信息
     *
     * @param id 安全阀台账ID
     * @return 结果
     */
    @Override
    public int deleteLedgerSafetyValveById(Long id)
    {
        return ledgerSafetyValveMapper.deleteLedgerSafetyValveById(id);
    }
}
